package com.cheer.dto;

import cn.hutool.core.date.DateUtil;
import com.cheer.enums.ApplicantStatusEnum;
import com.cheer.enums.RegisterStatusEnum;
import com.cheer.enums.TitleEnum;
import com.cheer.enums.TitleStatusEnum;
import com.cheer.vo.ApplicantRegisterVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.text.NumberFormat;
import java.util.Date;

@Data
@Accessors(chain = true)
public class ApplicantReviewPageDTO {

    private Long accountId;

    private Long applicantId;

    private String applicantName;

    private String orgName;

    private String phoneAccount;

    private String contactPerson;

    private Integer personNumber;

    private Integer youthNumber;

    private Integer registerTitle;

    private Integer title;

    @ApiModelProperty("获取的星星数量")
    private Integer starNum;

    private Date createTime;

    private Integer reviewType;

    public ApplicantRegisterVO build() {
        ApplicantRegisterVO applicantRegisterVO = new ApplicantRegisterVO();
        applicantRegisterVO.setAccountId(accountId);
        applicantRegisterVO.setApplicantId(applicantId);
        applicantRegisterVO.setApplicantName(applicantName);
        applicantRegisterVO.setOrgName(orgName);
        applicantRegisterVO.setPhoneAccount(phoneAccount);
        applicantRegisterVO.setContactPerson(contactPerson);
        applicantRegisterVO.setStarNum(starNum);
        applicantRegisterVO.setPersonNumber(personNumber);
        applicantRegisterVO.setYouthNumber(youthNumber);
        NumberFormat nt = NumberFormat.getPercentInstance();
        if(youthNumber == 0 || personNumber == 0){
            applicantRegisterVO.setYouthPercent(nt.format(0));
        }else{
            applicantRegisterVO.setYouthPercent(nt.format(1.0 * youthNumber / personNumber));
        }
        applicantRegisterVO.setApplicantStatus(registerTitle > TitleEnum.NO.getType() ? ApplicantStatusEnum.AWARD.getType()
                : ApplicantStatusEnum.NEW.getType());
        if (applicantRegisterVO.getApplicantStatus() == ApplicantStatusEnum.AWARD.getType()) {
            if (title == TitleEnum.NO.getType()) {
                applicantRegisterVO.setTitle(registerTitle);
            } else {
                applicantRegisterVO.setTitle(title);
            }
        }
        applicantRegisterVO.setRegisterTime(DateUtil.formatDate(createTime));
        applicantRegisterVO.setStatus(title == TitleEnum.NO.getType() ?
                TitleStatusEnum.TO_BE_TITLED.getType() : TitleStatusEnum.TITLED.getType());
        applicantRegisterVO.setReviewType(reviewType);
        applicantRegisterVO.setRegisterTitle(registerTitle);
        return applicantRegisterVO;
    }

}
